CXX=g++
CXXFLAGS=-Wall -Wextra -Winit-self -Wstrict-aliasing=2 -Wfloat-equal -Wno-comment -Wno-missing-field-initializers -Wno-unused -fPIC -DPTRACING=1 -D_REENTRANT -D_GNU_SOURCE=1 -felide-constructors -Wreorder -I../common/include -Iinclude -I../embedding/include -I../protocols/include
LDFLAGS=
LIBS=-L../protocols/build-$(ARCH) -lprotocols -L../embedding/build-$(ARCH) -lembedding -L../common/build-$(ARCH) -lcommon -lfftw3 -lgsl -lgslcblas -lcryptopp
#LIBS += -lboost_thread-mt
ifeq ($(DEBUG_BUILD),yes)
CXXFLAGS += -ggdb -O0 -DDEBUG
endif # DEBUG_BUILD
CXXFLAGS += $(CXXFLAGS_ARCH)
LDFLAGS += $(LDFLAGS_ARCH)
ifndef $(ARCH)
ARCH = default
endif

RM=rm
RMFLAGS=-rf
MKDIR=mkdir
AR=ar
ARFLAGS=rcs

SOURCE_DIR=src

BUILD_DIR=build-$(ARCH)

SOURCE_FILES=$(shell cd $(SOURCE_DIR) ; ls *.cxx)

LIBOUT=$(BUILD_DIR)/libfactory.a

OBJ=$(SOURCE_FILES:%.cxx=$(BUILD_DIR)/%.o)

default: debug

release: all

all: $(LIBOUT)

debug:
	$(MAKE) DEBUG_BUILD=yes all
	
$(LIBOUT): init $(OBJ)
	$(AR) $(ARFLAGS) $(LIBOUT) $(OBJ)
	
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.cxx
	$(CXX) -c $(CXXFLAGS) -o $@ $<

init:
	@if [ ! -d $(BUILD_DIR) ] ; then $(MKDIR) -p $(BUILD_DIR) ; fi

.PHONY: clean

clean:
	$(RM) $(RMFLAGS) $(BUILD_DIR)

